package com.smz.service.impl;

import com.smz.dao.ProductOrderDAO;
import com.smz.entity.PageEntity;
import com.smz.entity.TProductOrder;
import com.smz.service.ProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductOrderServiceImpl implements ProductOrderService {

    @Autowired
    private ProductOrderDAO productOrderDAO;

    @Override
    public List<TProductOrder> findAll() {
        return productOrderDAO.selectAll();
    }

    @Override
    public void addOrder(TProductOrder productOrder) {
        productOrderDAO.insertOrder(productOrder);
    }

    @Override
    public int selectRoleCount() {
        return productOrderDAO.selectOrderCount();
    }

    @Override
    public PageEntity<TProductOrder> findOrderPage(Integer current) {
       if (current<1){
           current=1;
       }
        int count = productOrderDAO.selectOrderCount();
        int pageCount = count % PageEntity.PAGE_SIZE == 0 ? count / PageEntity.PAGE_SIZE : count / PageEntity.PAGE_SIZE + 1;
        List<TProductOrder> data = productOrderDAO.selectOrderByPage((current-1)* PageEntity.PAGE_SIZE,PageEntity.PAGE_SIZE);

        //data数据要放第一个要不然无法识别参数类型
        return new PageEntity<>(data,current,count,pageCount);
    }

    @Override
    public void modifyOrderById(int id,String orderStatus) {
        if (orderStatus.equals("-1")){
            orderStatus="-4";
        }
        productOrderDAO.updateOrderById(id,orderStatus);
    }

//    @Override
//    public void modifyProductById(int id, String productStatus) {
//        productOrderDAO.updateProductById(id,productStatus);
//    }

    @Override
    public List<TProductOrder> findOrderByOrderId(Integer orderId) {
        return productOrderDAO.selectOrderByOrderId(orderId);
    }

    @Override
    public List<TProductOrder> findProductStatus(String productStatus) {
        return productOrderDAO.selectProductStatus(productStatus);
    }

    @Override
    public List<TProductOrder> findOrderByTime(String dealTime) {
        return productOrderDAO.selectOrderByTime(dealTime+"%");
    }

    @Override
    public List<TProductOrder> findOrderByIdTime(Integer id, String dealTime) {
        return productOrderDAO.selectOrderByIdTime(id,dealTime);
    }

    @Override
    public void modifyStatusById(TProductOrder tProductOrder) {
        productOrderDAO.updateStatusById(tProductOrder);
    }

}
